package main

import (
	"encoding/json"
	"fmt"
	"net/http"
	"owl-k8sClient/common/types"
	"time"
)

func homePage(w http.ResponseWriter, r *http.Request) {
	var tsd types.TimeSeriesData
	if r.Body == nil {
		http.Error(w, "Please send a request body", 400)
		return
	}
	err := json.NewDecoder(r.Body).Decode(&tsd)
	if err != nil {
		http.Error(w, fmt.Sprintf(`{"status":"%s"}`, err.Error()), 400)
		return
	}
	tsd.Timestamp = time.Now().Unix()
	lg.Info("get json data", tsd)
	agent.SendChan <- tsd

	w.Write([]byte(`{"status":"ok"}`))

}
